package one.stand.controller;

import com.jmp.api.crm.dto.ArticleTypeSelectResponse;
import com.jmp.autocofiguration.web.interceptor.SecurityAuthCheck;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import one.stand.dto.ConvertUtils;
import one.stand.mapper.ArticleApiCrmPcMapper;
import one.stand.model.ArticleType;
import one.stand.model.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cjr
 */
@Api(description = "文章分类")
@RestController
@RequestMapping("crmPc/article/type")
@Slf4j
public class ArticleTypeController {
    @Autowired
    private ArticleApiCrmPcMapper articleApiCrmPcMapper;

    @ApiOperation(value = "选择列表")
    @PostMapping("select")
    @SecurityAuthCheck
    public ResultModel<ArticleTypeSelectResponse> select() {

        List<ArticleType> articleTypeList = articleApiCrmPcMapper.selectType(null);
        List<ArticleTypeSelectResponse.Type> types = ConvertUtils.list(articleTypeList, articleType -> ArticleTypeSelectResponse.Type.builder()
                .id(articleType.getId())
                .name(articleType.getName())
                .build());

        ArticleTypeSelectResponse response = ArticleTypeSelectResponse.builder()
                .types(types)
                .build();
        return ResultModel.success(response);
    }

}
